PWD=$(shell pwd)
CC = gcc

INCLUDE=-I$(PWD)/include
ENDIAN = little
OUTPUT=$(PWD)/debug/

ifeq ($(shell getconf LONG_BIT), 32)
    CFLAGS += -m32
    LDFLAGS += -ldl -lrt -lpthread
else
    CFLAGS += -m64
    LDFLAGS += -ldl -lrt -lpthread
endif


ifeq ($(LSM_KYLINV10), yes)
	EXTRA_CFLAGS += -DLSM_KYLINV10
endif

ifeq ($(LSM_UOS), yes)
	EXTRA_CFLAGS += -DLSM_UOS
endif

MODULE_SUF=.ko
EPP_KERNEL_TARGET=eppsec
EPP_SERVICE_TARGET=epp_service

EPP_KERNEL_DIR=$(PWD)/kernel
EPP_SERVICE_DIR=$(PWD)/service


EPP_KERNEL_SRCS=$(wildcard $(EPP_KERNEL_DIR)/*.c)
EPP_KERNEL_OBJS=$(patsubst %.c,%.o,$(EPP_KERNEL_SRCS))

EPP_SERVICE_SRCS=$(wildcard $(EPP_SERVICE_DIR)/*.c)
EPP_SERVICE_OBJS=$(patsubst %.c,%.o,$(EPP_SERVICE_SRCS))

all:
	@make project

project:mk_need_dir kernel

service:phony mk_need_dir
	make -C  $(EPP_SERVICE_DIR) OUTPUT=$(OUTPUT) EPP_SERVICE_TARGET=$(EPP_SERVICE_TARGET)

kernel:phony mk_need_dir
	make -C $(EPP_KERNEL_DIR) OUTPUT=$(OUTPUT) EPP_KERNEL_TARGET=$(EPP_KERNEL_TARGET) MODULE_SUF=$(MODULE_SUF)

mk_need_dir:
	-mkdir -p $(OUTPUT)

clean:
	-rm -r $(OUTPUT)
	-make -C $(EPP_KERNEL_DIR) OUTPUT=$(OUTPUT) EPP_KERNEL_TARGET=$(EPP_KERNEL_TARGET) clean
	-make -C $(EPP_SERVICE_DIR) OUTPUT=$(OUTPUT) clean
phony:  
.PHONY:
